package domain.service;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class SiteInfo {
	public SiteInfo(String name_domain)
	{
		try {
			URL dataURL = new URL("http://"+name_domain);
			
			String charset   = "UTF-8";
			
			name_domain = name_domain.replaceAll("www.", "");
			
		    HttpURLConnection connection = (HttpURLConnection) dataURL.openConnection();
		    connection.setInstanceFollowRedirects(true);

		    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String content = "";
			connection.getInputStream().mark(20000);
			while(1==1)
			{
				String str = reader.readLine();
				if(str==null) break;
				content+=str;
				
			}
			

			String server = connection.getHeaderField("Server");
			String powerBy = connection.getHeaderField("X-Powered-By");
			
			Document doc = Jsoup.parse(content);
			
			System.out.println(doc);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void main( String args[])
	{
		new SiteInfo("mintworks.com");
	}
}
